Skip to content

fix: only create arrays for array index tokens in set - #69

Open
bardrop wants to merge 1 commit into
janl:mainfrom
bardrop-oss:fix/array-index-tokens
Open

bardrop wants to merge 1 commit into
janl:mainfrom
bardrop-oss:fix/array-index-tokens

Conversation

@bardrop

@bardrop bardrop commented Nov 20, 2026

Copy link
Copy Markdown

Fixes #68.

set made a missing container an array when the next token was < Infinity. That is true for -1, 1.5, 01, 0x1f, 1e3 and ' ', so the value went onto an array as a named property and JSON.stringify dropped it ({"a":[]}).

Now an array is only created when the next token is an RFC 6901 array index: 0, digits without a leading zero, or -. Everything else gets an object. Number tokens in array pointers still work (['', 'a', 0, 'b'] → {"a":[{"b":1}]}).

Tests: new cases in test.js for both kinds of tokens. They fail on main and pass with the change. npm test (standard + tests) is green.

A missing container became an array whenever the next token was < Infinity,
so tokens like -1, 1.5, 01, 0x1f or ' ' were written as named properties on
an array and lost in JSON. Follow RFC 6901: only 0, digits without a leading
zero, or - make an array.

Fixes janl#68
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

set() creates an array for non-index tokens like -1, 1.5, 01, 0x1f, so the value is lost in JSON

1 participant